package com.example.entity;

/**
 * @author 胡帅博
 * @date 2020/9/29 10:48
 * <p>
 * <p>
 * 对于不同数量的
 *
 *
 *
 * 一个菜谱两种技法，多种食材
 *
 *
 */
final public class CalRecipe{

    //缓存中对应的索引  将所有会用到的菜谱 的id压缩成从0开始的联系数值后得到的
    public int index;

    // 根据 recipeId和count生成
    public int id;

    //做的份数
    final public int count;
    final public int recipeId;
    final public String name;
    final public int stirfry;
    final public int boil;
    final public int knife;
    final public int fry;
    final public int bake;
    final public int steam;
    final public int rarity;
    //单价
    final public int price;
    //专精价格
    final public int exPrice;
    //菜谱属性     肉 面 菜 鱼
    public int[] tags;
    //技法要求  按照 烤，煮，切，炸，烤，蒸的方式排列
    public int[] attributeTags;




    public CalRecipe(Recipe recipe, int count) {
        this.count = count;
        this.recipeId = recipe.getRecipeId();
        this.name = recipe.getName();
        this.stirfry = recipe.getStirfry();
        this.boil = recipe.getBoil();
        this.knife = recipe.knife;
        this.fry = recipe.fry;
        this.bake = recipe.bake;
        this.steam = recipe.steam;
        this.price = recipe.price;
        this.exPrice = recipe.exPrice;
        this.rarity=recipe.getRarity();
        this.tags = recipe.getTags();
        // 菜谱id最大值不超过10000<2的14次方  菜谱数量的最大值不会超过60<2的6次方，
        // 因此底14位存菜谱id，接着6位存菜谱数量
        // 可以保证一个菜谱和数量的搭配， 生成的id不会存在重复情况
        this.id = count << 14 | recipeId;
    }

    /**
     * 通过菜谱id和菜谱数量 确定菜谱是否相同
     */
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof CalRecipe)) return false;

        CalRecipe calRecipe = (CalRecipe) o;

        if (count != calRecipe.count) return false;
        return recipeId == calRecipe.recipeId;
    }

    /**
     * count<<14|recipeid;
     */
    @Override
    public int hashCode() {
        return id;
    }

    @Override
    public String toString() {
        return "{" +
                "\"recipe\" : \"" + name +"\""+
                ", \"count\" :" +  count +
                '}';
    }
}
